package com.wzapp.sitposture.event;

import com.wzapp.sitposture.usercenter.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.HashMap;

/**
 * Created by qianglong on 2018/2/28.
 */
@Slf4j
@Component
public class BusinessEventListener implements ApplicationListener<BusinessEvent> {

    @Autowired
    UserService userService;

    @Async
    @Override
    public void onApplicationEvent(BusinessEvent event) {
        String bizCode = event.getBizCode();
        HashMap<String, Object> param = event.getParam();
        log.info("=============BusinessEventListener==============" + bizCode);

        switch (bizCode) {
            case "userLogin":
                userService.publishLoginLogEvent(param);
                break;
            case "userLogOut":
                userService.publishLogOutLogEvent(param);
                break;
            default:
        }
    }

}
